//
//  NewsPushViewController.m
//  EggSteward
//
//  Created by 王道林 on 16/9/8.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "NewsPushViewController.h"
#import "DLMacro.h"
#import "BaseTableView.h"
#import "SetTableViewCellT.h"
@interface NewsPushViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) NSArray *arrData;
@property (nonatomic, assign) BOOL switchRecord;
@end

@implementation NewsPushViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"消息推送设置";
    _arrData = @[@"接收新消息通知", @"声音", @"震动"];
    [self createSubview];
}

- (void)createSubview
{
    _tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, -35, VIEW_WIDTH, self.view.frame.size.height) style:UITableViewStyleGrouped];
    _tableView.bounces = NO;
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerClass:[SetTableViewCellT class] forCellReuseIdentifier:@"reuse"];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_switchRecord == 1) {
        return 3;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        SetTableViewCellT *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
        // switch的实现部分
        cell.BlockOn = ^(BaseSwitch *switchDe)
        {
            _switchRecord = 1;
            [_tableView reloadData];
        };
        cell.BlockOff = ^(BaseSwitch *switchDe)
        {
            _switchRecord = 0;
            [_tableView reloadData];
        };
        cell.labelTitle.text = _arrData[indexPath.row];
        return cell;
    } 
    SetTableViewCellT *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    cell.BlockOn = ^(BaseSwitch *switchDe)
    {
       
    };
    cell.BlockOff = ^(BaseSwitch *switchDe)
    {
       
    };
    cell.labelTitle.text = _arrData[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

// 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SetTableViewCellT *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (indexPath.row == 0) {
        cell.switchDelete.on = !cell.switchDelete.on;
        if (cell.switchDelete.on) {
            _switchRecord = 1;
            [_tableView reloadData];
        } else
        {
            _switchRecord = 0;
            [_tableView reloadData];
        }
    } else
    {
        cell.switchDelete.on = !cell.switchDelete.on;
    }
}


#pragma mark - 点击cell的时候有颜色显示
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    SetTableViewCellT *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:0.886 green:1.000 blue:0.066 alpha:1.000];
}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    SetTableViewCellT *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
